#!/bin/bash

if [ "$EUID" -ne 0 ]; then
	echo "错误：此脚本必须以 root 用户身份运行" >&2
	exit 1
fi

if command -v nvim &>/dev/null; then
	nvim_path=$(command -v nvim)
else
	echo "nvim not install"
	exit 1
fi

echo "[ -x $nvim_path ] && export EDITOR=$nvim_path" | tee /etc/profile.d/default_editor.sh >/dev/null

if type update-alternatives &>/dev/null; then
	update-alternatives --install /usr/bin/editor editor $nvim_path 100 --slave /usr/share/man/man1/editor.1.gz editor.1.gz /usr/share/man/man1/nvim.1.gz
fi

# bash -c "$(curl -fsSL https://gitee.com/hevey88/install_script/raw/main/neovim_default_editor.sh)"
